<table id="admin_applyInfo" data-options="fit:true"></table>
<script>
$(function(){
	$('#admin_applyInfo').datagrid({
		url:'../applyInfo/Get_AllApplyInfo',
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'aok',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'aids',title:'',width:100,align:'center',checkbox:true},
			{field:'aid',title:'申请编号',width:50,align:'center'},
			{field:'mid',title:'维修员编号编号',width:100,align:'center'},
			{field:'laddr',title:'维修地点',width:300,align:'center'},
			{field:'aok',title:'是否通过',width:80,align:'center',sortable:true,formatter: function(value,row,index){
					if (row.aok==1){
						return "已通过";
					} else {
						return "未通过";
					}
				}
			},
			{field:'astatus',title:'是否维修',width:80,align:'center',sortable:true,
				formatter: function(value,row,index){
					if (row.astatus==1){
						return "已维修";
					} else {
						return "未维修";
					}
				}	
			},
			{field:'_operate',title:'操作',width:100,align:'center',formatter:function(value, rowData, index){
				return "<a class='icon-file icon-padding' href=\"javascript:detailStaff("+rowData.mid+")\">查看维修员信息</a>";
			}}
		]],
		toolbar: [{
			iconCls: 'icon-ok',
			text:'通过',
			handler: function(){
				var aids=$('#admin_applyInfo').datagrid('getSelections');
				if(aids.length==0){
					$.messager.alert('错误提示','请选择操作项!','error');
					return;
				}
				var aok=aids[0].aok;
				if(aok==1){
					$.messager.alert('错误提示','请勿重复操作!','error');
					$('#admin_applyInfo').datagrid('clearSelections');
					return;
				}
				if(aids.length>1){
					$.messager.alert('错误提示','事关重大,请逐项选择!','error');
					$('#admin_applyInfo').datagrid('clearSelections');
				}else{
					var aid=aids[0].aid;
					var laddr = aids[0].laddr;
					$.ajax({
					    url: "../applyInfo/updateAok",    //请求的url地址
					    dataType: "json",   //返回格式为json
					    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
					    type: "POST", 
					    data: { "aid" : aid , "laddr" : laddr},    //参数值
					    success: function(data) {
					    	if(parseInt($.trim(data.obj))>=1){
					    		$.messager.show({
									title:'成功提示',
									msg:'修改信息成功！',
									timeout:3000,
									showType:'slide'
								});
								$('#admin_applyInfo').datagrid("reload");
					    	}else{
					    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
					    	}
					    },
					});
				}
			}
		},'-',{
			iconCls: 'icon-edit',
			text:'删除',
			handler: function(){
				var aids=$('#admin_applyInfo').datagrid('getSelections');
				if(aids.length==0){
					$.messager.alert('错误提示','请选择操作项!','error');
					return;
				}
				var astatus=aids[0].astatus;
				if(astatus==1){
					$.messager.alert('错误提示','请不要破坏维护记录!','error');
					$('#admin_applyInfo').datagrid('clearSelections');
					return;
				}
				if(aids.length>1){
					$.messager.alert('错误提示','事关重大,请逐项选择!','error');
					$('#admin_applyInfo').datagrid('clearSelections');
				}else{
					var aid=aids[0].aid;
					$.ajax({
					    url: "../applyInfo/delApplyInfo",    //请求的url地址
					    dataType: "json",   //返回格式为json
					    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
					    type: "POST", 
					    data: { "aid": aid},    //参数值
					    success: function(data) {
					    	if(parseInt($.trim(data.obj))>=1){
					    		$.messager.show({
									title:'成功提示',
									msg:'删除信息成功！',
									timeout:3000,
									showType:'slide'
								});
								$('#admin_applyInfo').datagrid("reload");
					    	}else{
					    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
					    	}
					    },
					});
				}
			}
		},'-',{
			iconCls: 'icon-reload',
			text:'刷新',
			handler: function(){
				$('#admin_applyInfo').datagrid("reload");
			}
		}]
	});
});
function detailStaff(mid){
	$.ajax({
	    url: "../maintainerInfo/selectOneStaff",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	    type: "POST", 
	    data: { "mid": mid},    //参数值
	    success: function(data) {
	    	console.info(data.obj);
	    	if(data!=null){
	    		$("#detail_Staff").dialog("open");
	    		$("#staff_id").val(data.obj.mid);
	    		$("#staff_name").val(data.obj.mname);
	    		$("#staff_age").val(data.obj.mage);
	    		if(data.obj.msex==1){
	    			$("#staff_sex").val("男");
	    		}else{
	    			$("#staff_sex").val("女");
	    		}
	    		$("#staff_tel").val(data.obj.mtel);
	    	}else{
	    		$.messager.alert('错误提示','网络错误,请稍后重试!','error');
	    	}
	    },
	});
}
</script>
<div id="detail_Staff" class="easyui-dialog" title="维护人员信息" style="width:400px;height:280px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label>编号：</label><input type="text" id="staff_id" disabled="disabled" style="text-align: center;">
		<br /> <br /> 
		<label>姓名：</label><input type="text" id="staff_name" disabled="disabled" style="text-align: center;">
		<br /> <br />
		<label>年龄：</label><input type="text" id="staff_age" disabled="disabled" style="text-align: center;">
		<br /> <br />
		<label>性别：</label><input type="text" id="staff_sex" disabled="disabled" style="text-align: center;">
		<br /> <br />
		<label>电话：</label><input type="text" id="staff_tel" disabled="disabled" style="text-align: center;">
	</p>
</div>
